# -*- coding: utf-8 -*-
# created on 2017/04/25
from sympy import S
from mathsolver.functions.base import BaseFunction, BaseIneq, BaseBelong, new_latex
from mathsolver.functions.hanshu.helper import check_func
from mathsolver.functions.hanshu.hengchengli import HengChengLiRenYiXing


class TuXiangShangXiaQiuCan(BaseFunction):
    """f(x)在g(x)上（下）方
    输入：f, g, 上下方"""

    def solver(self, *args):
        f, g, shangxia = check_func(args[0]), check_func(args[1]), args[2]
        op = '>' if "上" in shangxia else '<'
        f_expr, g_expr = f.expression, g.expression

        dingyi_interval = self.search(f.var)
        if not dingyi_interval:
            dingyi_interval = S.Reals

        self.steps.append(["", "由题意知在区间 %s 上 %s %s %s 恒成立 " % (new_latex(dingyi_interval), new_latex(f_expr), op, new_latex(g_expr))])
        hcl_solver = HengChengLiRenYiXing().solver(BaseIneq([f_expr, op, g_expr]), BaseBelong([f.var, '\\in', dingyi_interval]))
        self.steps.extend(hcl_solver.steps)
        self.output = hcl_solver.output
        self.label.add("恒成立问题")
        return self


if __name__ == '__main__':
    pass
